<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     Pagizer
 * @subpackage  backoffice
 */

/**
 * Ajax action to clear logs
 * Used by clearLogs() in jQueryBackend.js
 */
class m_backoffice_actions_AjaxClearLogsAction extends f_core_Action
{
	public function execute()
	{
        $files = f_file_Resolver::getInstance()->fromDirectory(realpath(LOGS_DIR))->setMask('*.log')->find();
        if(count($files) > 0)
        {
            foreach($files as $file)
            {
                unlink($file);
            }
        }
        echo $this->getLocale('backoffice.locales.filesDeleted');
	}

	public function validate()
	{
		return $this->getUserContext()->hasRight("backoffice_accessSystem");
	}

	public function errorHandler()
	{
		return null;
	}
}